package com.miyake.client.datamanage;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Panel;
import com.miyake.client.DataService;
import com.miyake.client.DataServiceAsync;

public class ShowFixedTable {
	private DataServiceAsync service = DataService.Util.getInstance();
	
	public ShowFixedTable(String key, Panel panel) {
		showTable(key, panel);
	}
	
	public ShowFixedTable(NodeProperty node, Panel panel) {
		showTable(node.getKey(), panel);
	}

	protected void showTable(String key, Panel panel) {
		final Grid grid = new Grid();
		panel.add(grid);
		service.getTable(key, new AsyncCallback<Table>() {
			@Override
			public void onFailure(Throwable caught) {	
			}

			@Override
			public void onSuccess(Table result) {
				int row = 0;
				grid.resize(result.getTextData().size(), result.getTextData().get(0).length);
				for (String[] s : result.getTextData()) {
					for (int col = 0; col < s.length; col++) {
						grid.setText(row, col, s[col]);
					}
					row++;
				}
			}
		});
	}
}
